/*
 * F6.c
 *
 *  Created on: 21/10/2012
 *      Author: Sarah
 */

#include "F6.h"

double F6minX = -32;
double F6maxX = 32;
int F6dimensions = 1000;
int nonSeparableGroupSize = 50;

double compute(double*x) {
	int i;
	double result;

	double* F6Ovector = createShiftVector(F6dimensions,F6minX,F6maxX);
	double* F6anotherz = (double*) malloc(sizeof(double) * F6dimensions);
	double* F6anotherz1 = malloc(sizeof(double) * F6dimensions);
	double* F6anotherz2 = malloc(sizeof(double) * F6dimensions);
	int* Pvector = createPermVector(F6dimensions);

	for (i = 0; i < F6dimensions; i++) {
		F6anotherz[i] = x[i] - F6Ovector[i];
	}

	for (i = 0; i < nonSeparableGroupSize; i++) {
		F6anotherz1[i] = F6anotherz[Pvector[i]];
	}

	for (i = nonSeparableGroupSize; i < F6dimensions; i++) {
		F6anotherz2[i - nonSeparableGroupSize] = F6anotherz[Pvector[i]];
	}

	result = rot_ackley(F6anotherz1, nonSeparableGroupSize) * 1e6
			+ ackley(F6anotherz2, F6dimensions - nonSeparableGroupSize);

	free(F6Ovector);
	free(F6anotherz);
	free(F6anotherz1);
	free(F6anotherz2);
	free(Pvector);
	return (result);
}

int F6GetDimensions() {
	return F6dimensions;
}
double F6GetGetMax() {
	return F6maxX;
}
double F6GetMin() {
	return F6minX;
}
